#@layout()

#define script()
<script>

    function trash(id) {
        ajaxGet("#(CPATH)/admin/article/doTrash/" + id);
    }

    function copy(id) {
        ajaxGet("#(CPATH)/admin/article/doCopy?articleId=" + id);
    }


    function draft(id) {
        ajaxGet("#(CPATH)/admin/article/doDraft/" + id);
    }


    function del(id) {
        if (confirm("确定要删除该页面吗？删除后不可恢复")) {
            ajaxGet("#(CPATH)/admin/article/doDel/" + id);
        }
    }

    function progress(id) {
        ajaxGet("#(CPATH)/admin/article/queryRunningProcessInstanceIds/" + id, function (resp) {
            if (resp.processInstanceIds && Array.isArray(resp.processInstanceIds)) {
                if (resp.processInstanceIds.length >= 1) {
                    var options = {
                        type: 2,
                        title: '查看审核进度',
                        anim: 2,
                        shadeClose: true,
                        shade: 0.3,
                        area: ['80%', '80%'],
                        content: "#(CPATH)/admin/flow/processDetailByProcessInstanceId?processInstanceId=" + resp.processInstanceIds[0],
                        end: function () {
                        }
                    };
                    layer.open(options);
                }
            }
        })
    }

    function cancelApproval(id) {
        if (confirm("确定要撤销审核吗？")) {
            ajaxGet("#(CPATH)/admin/article/doCancelApproval/" + id);
        }
    }

</script>

#end


#define content()
<!-- Content Header (Page header) -->
<section class="content-header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-6">

                <div class="row mb-2">
                    <div class="col-sm-12">
                        <h1>
                            文章管理
                            <small data-toggle="tooltip" title="可以查看所有文章，鼠标移到文章标题上，可以对其编辑或删除等操作" data-placement="bottom"
                                   data-trigger="hover"><i class="nav-icon far fa-question-circle"></i></small>
                            <small> 首页 / 文章 / 文章管理</small>
                        </h1>
                    </div>
                </div>

                <div class="row">
                    <div class="col-12" style="padding-top: 20px">
                        <a href="#(CPATH)/admin/article/list">全部 (#(totalCount ??))</a> |
                        <a href="?status=normal">已发布 (#(normalCount ?? 0 ))</a> |
                        <a href="?status=underreview">审核中 (#(underReviewCount ?? 0))</a> |
                        <a href="?status=rebut">驳回 (#(rebutCount ?? 0))</a> |
                        <a href="?status=refuse">已拒绝 (#(refuseCount ?? 0))</a> |
                        <a href="?status=draft">草稿 (#(draftCount ?? 0))</a> |
                        <a href="?status=trash" style="color: #a00">垃圾箱 (#(trashCount ?? 0))</a>
                    </div>
                </div>

            </div>
            <div class="col-sm-6 ">
                <div class=" float-sm-right" style="padding-top: 45px">
                    <a href="./write" type="button" class="btn btn-primary"><i class="fas fa-plus"></i>新建</a>
                </div>
            </div>
        </div>

    </div><!-- /.container-fluid -->
</section>


<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="card card-outline card-primary">
            <div class="card-header">
                <form class=" admin-search-panel" action="" method="get">
                    <div class="row">
                        <div class="form-group col-lg-2">
                            <input type="text" class="form-control" placeholder="文章标题" name="title"
                                   value="#para('title')">
                        </div>
                        <div class="form-group col-lg-2">
                            <input type="text"
                                   data-range="true"
                                   data-multiple-dates-separator=" ~ "
                                   class="form-control date" placeholder="发布时间开始 ~ 结束" name="dateRange"
                                   value="#para('dateRange')">
                        </div>

                        <div class="form-group col-lg-2">
                            <select class="form-control" name="categoryId">
                                <option value="">全部分类</option>
                                #for(category : categories)
                                <option value="#(category.id ??)" #selectedIf(category.id== numberPara(
                                'categoryId'))>#(category.layerString) #(category.title ??)</option>
                                #end
                            </select>
                        </div>

                        <div class="input-group col-lg-2">
                            <input type="text" class="form-control" placeholder="发布用户" readonly id="userName"
                                   name="userName" value="#para('userName')">
                            <div class="form-control-clear d-none"><i class="fas fa-times"></i></div>
                            <input type="hidden" class="clear" name="userId" id="userId" value="#para('userId')">
                            <div class="input-group-append">
                                <button class="btn input-group-text" type="button" open-type="layer"
                                        data-layer-title="请选择用户"
                                        data-layer-content="#(CPATH)/commons/select/user"
                                        data-layer-binds="#userName:nickname,#userId:id"><i
                                        class="fas fa-user-plus"></i></button>
                            </div>
                        </div>

                        <div class="form-group col-lg-2">
                            <button type="submit" class="btn btn-primary ">查询</button>
                            <button type="reset" class="btn btn-default">重置</button>
                        </div>
                    </div>

                    <!-- /.card-body -->
                </form>
            </div> <!-- /.card-body -->
            <div class="card-body p-0">

                <table class="table table-striped table-action">
                    <thead>
                    <tr>
                        <th style="width: 10px">
                            <input class="tableCheckAll" type="checkbox">
                        </th>
                        <th style="width: 100px">ID</th>
                        <th style="width: 450px">标题</th>
                        <th>分类</th>
                        <th>标签</th>
                        <th>样式</th>
                        <th style="width: 100px">作者</th>
                        <th style="width: 50px"><i class="far fa-comment-dots"></i></th>
                        <th style="width: 50px"><i class="far fa-eye"></i></th>
                        <th style="width: 110px">发布时间</th>
                    </tr>
                    </thead>
                    <tbody>


                    #for(item : page.list ??)
                    <tr>
                        <td>
                            <input name="tableItem" type="checkbox" value="#(item.id)"/>
                        </td>
                        <td>#(item.id)</td>
                        <td>
                            <strong>
                                <a href="#(CPATH)/admin/article/write/#(item.id)">#(item.title ??)</a>
                                #if(item.isNormal())
                                <span style="color: #00c054"> （已发布）</span>
                                #elseif(item.isUnderReview())
                                <span style="color: #007bff"> （审核中... ）</span>
                                #elseif(item.isRefuse())
                                <span style="color: #bb393a;"> （审核不通过   #(item.option('lastFlowComment',' : '))）</span>
                                #elseif(item.isRebut())
                                <span style="color: #bb393a;"> （被驳回   #(item.option('lastFlowComment',' : '))）</span>
                                #elseif(item.isDraft())
                                （草稿）
                                #end

                                #if(item.withRecommend ??)<span class="attr-tag">荐</span>#end
                                #if(item.withHot ??)<span class="attr-tag">热</span>#end
                                #if(item.withTop ??)<span class="attr-tag">顶</span>#end
                                #if(item.withLeadNews ??)<span class="attr-tag">头条</span>#end

                            </strong>
                            <div class="jp-action-card">
                                #if(item.isNormal())
                                <div class="jp-action-body">
                                    <a href="#(CPATH)/admin/article/write/#(item.id)">编辑</a> |
                                    <a href="javascript:;" onclick="draft('#(item.id??)')">草稿</a> |
                                    <a href="javascript:;" onclick="copy('#(item.id??)')">复制</a> |
                                    <a href="javascript:;" onclick="trash('#(item.id??)')" class="red-action">垃圾箱</a> |
                                    <a href="#option('web_domain')#(item.url ??)" target="_blank"
                                       class="red-action">浏览</a>
                                    #staticize(item.url,"|")
                                </div>
                                #elseif(item.isUnderReview())
                                <div class="jp-action-body">
                                    <a href="#(CPATH)/admin/article/write/#(item.id)">查看/编辑</a> |
                                    <a href="javascript:;" onclick="copy('#(item.id??)')">复制</a> |
                                    <a href="javascript:;" onclick="progress('#(item.id??)')">审核进度</a> |
                                    <a href="javascript:;" onclick="cancelApproval('#(item.id??)')" class="red-action">撤销审核</a>
                                </div>
                                #elseif(item.isRebut())
                                <div class="jp-action-body">
                                    <a href="#(CPATH)/admin/article/write/#(item.id)">编辑</a> |
                                    <a href="javascript:;" onclick="copy('#(item.id??)')">复制</a> |
                                    <a href="javascript:;" onclick="cancelApproval('#(item.id??)')" class="red-action">撤销审核</a>
                                </div>

                                #elseif(item.isDraft())
                                <div class="jp-action-body">
                                    <a href="#(CPATH)/admin/article/write/#(item.id)">编辑</a> |
                                    <a href="javascript:;" onclick="copy('#(item.id??)')">复制</a> |
                                    <a href="javascript:;" onclick="trash('#(item.id??)')" class="red-action">垃圾箱</a>
                                </div>
                                #else
                                <div class="jp-action-body">
                                    <a href="javascript:;" onclick="draft('#(item.id??)')">还原到草稿箱</a> |
                                    <a href="javascript:;" onclick="del('#(item.id??)')" class="red-action">永久删除</a>
                                </div>
                                #end
                            </div>
                        </td>
                        <td>
                            #articleCategories(item.id,"category")
                            #for(category : categories)
                            <a href="#option('web_domain')#(category.url ??)" target="_blank">#(category.title ??)</a>
                            #if(!for.last) , #end
                            #end
                            #end
                        </td>
                        <td>
                            #articleCategories(item.id,"tag")
                            #for(category : categories)
                            <a href="#option('web_domain')#(category.url ??)" target="_blank">#(category.title ??)</a>
                            #if(!for.last) , #end
                            #end
                            #end
                        </td>
                        <td>#(item.style ?? "默认")</td>
                        <td>#(item.user.nickname ?? item.user.username ??)</td>
                        <td>
                            <a href="#(CPATH)/admin/article/comment/list?articleId=#(item.id)">
                                #(item.comment_count ??)
                            </a>
                        </td>
                        <td>#(item.view_count ??)</td>
                        <td>#date(item.created ??)</td>
                    </tr>
                    #end

                    </tbody>
                </table>


                <div class="card-footer">
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="row">

                                <div class="form-group">
                                    <div class="form-check">
                                        <input class="form-check-input tableCheckAll" id="checkall" type="checkbox">
                                        <label class="form-check-label" for="checkall">全选</label>
                                    </div>
                                </div>
                                <div class="form-group col-lg-3">
                                    <select class="form-control" name="action">
                                        <option value="">请选择...</option>
                                        <option value="doDelByIds" open-type="del-confirm">
                                            批量删除
                                        </option>
                                    </select>
                                </div>

                                <div class="form-group col-lg-3">
                                    <button type="button" class="btn btn-outline-primary batchExec">批量操作</button>
                                </div>
                            </div>
                        </div>

                        <div class="col-sm-6">
                            #@_paginate()
                        </div>
                    </div>
                </div>
                <!-- /.card-footer -->


            </div><!-- /.card-body -->


        </div>
    </div><!-- /.container-fluid -->
</section>
<!-- /.content -->

#end